<template>
  <a-drawer
    title="变更导师"
    width=450
    placement="right"
    :closable="false"
    @close="onClose"
    :visible="planReviewVisible"
    style="height: calc(100% - 55px);overflow: auto;padding-bottom: 53px;">
    <a-form :form='form'>
      <a-row :gutter="48">
        <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="准考证号">
              <a-input placeholder="请输入..."  v-model="postParams.ksbh" disabled />
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="考生姓名">
              <a-input placeholder="请输入..."  v-model="postParams.ksxm" disabled />
            </a-form-item>
          </a-col>
          <!-- <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="录取研究方向">
              <a-select showSearch optionFilterProp="children" :allowClear="true" v-model="postParams.bkyjfxm" @change='yjfxChange' disabled>
                <a-select-option v-for="i in selectMenu.yjfx" :key="i.id" :value="i.yjfxm">{{ i.yjfxmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col> -->
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="录取研究方向">
              <a-input placeholder="请输入..."  v-model="postParams.bkyjfxmc" disabled />
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="录取导师">
              <a-select showSearch optionFilterProp="children" :allowClear="true" v-model="postParams.lqdsId">
                <a-select-option v-for="i in selectMenu.ds" :key="i.id" :value="i.id">{{ i.gh + '-' +i.xm }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="录取院系">
              <a-input placeholder="请输入..."  v-model="postParams.bkyxsmc" disabled />
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="录取专业代码">
              <a-input placeholder="请输入..."  v-model="postParams.lqzym" disabled />
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="录取专业">
              <a-input placeholder="请输入..."  v-model="postParams.bkzymc" disabled />
            </a-form-item>
          </a-col>
      </a-row>
    </a-form>
    <div class="drawer-bootom-button">
      <a-button style="margin-right: .8rem" @click="onClose">取消</a-button>
      <a-button @click="handleSubmit" type="primary" :loading="loading">保存</a-button>
    </div>
  </a-drawer>
</template>

<script>
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'

const formItemLayout = {
  labelCol: { span: 3 },
  wrapperCol: { span: 18 }
}

const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072','TYPE0362','TYPE0347','TYPE0301']
export default {
  props: {
    planReviewVisible: {
      default: false
    },
    info: {
      default: () => ({})
    }
  },
  components: {
    STable
  },
  data () {
    return {
      formItemLayout,
      loading: false,
      postParams: {
       ksbh:'',
       ksxm:'',
       bkyjfxmc:'',
       bkdsym:'',
       lqlbm:'',
       pymsm:'',
       dasfzr:'',
       xz:'',
       blrxzgnx:'',
       dxwpdw:''
      },
      selectMenu: {
        yx: [], // 院系
        yjfx:[],
        ds:[],
        sfzr:[
          {
          id:'02',
          name:'是'
          },
           {
          id:'01',
          name:'否'
          },
        ]
      },
      isWp:false,
      isDisable:false
    }
  },
  beforeCreate(){
    this.form = this.$form.createForm(this)
  },
  watch: {
    info () {
      console.log(this.info)
      // this.isWp = ''
      // this.isDisable = ''
      //   this.form.resetFields()
      this.postParams = this.info
      this.yjfxChange(this.info.bkyjfxm)
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] ,// 年级
      TYPE0362:state => state.app['TYPE0362'],
      TYPE0347:state => state.app['TYPE0347'],
      TYPE0301:state => state.app['TYPE0301']
    })
  },
  created () {
    
    this.initSelectMenu()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      console.log(this.info)
      // let allRequest = [
      //   this.$api.base.collegeAll()
      // ]
      // Promise.all(allRequest).then(res => {
      //   this.selectMenu.yx=res[0].data
      // })
    },
    reset () {
      this.data = []
    },
    // 选择院系
    yxChange (code) {
    },
    // 选择招生年度
    zsndChange () {

    },
    lqChange(code){
      if(code){
        if(code == '12'){
          this.isWp = true
          this.isDisable = false
        }else if(code == '11'){
          this.isWp = false
          this.isDisable = true  
        }else {
          this.isWp = false
          this.isDisable = false
        }
         this.$nextTick(() => {
        this.form.validateFields(['dxwpdw'], { force: true });
      });
      }
    },
    yjfxChange(code){
      // this.$set(this.postParams, 'lqds', '')
      this.form.setFieldsValue({'lqds':''})
      this.$set(this.selectMenu, 'ds', [])
      this.$api.base.getGuide({
        zsxn:this.postParams.zsxn,
        ssyxm: this.postParams.bkyxsm,
        zym: this.postParams.lqzym,
        yjfxm:this.postParams.lqyjfxm
      }).then(res => {
        this.$set(this.selectMenu, 'ds', res.data)
      })
    },
    // 关闭
    onClose () {
      this.reset()
      this.$emit('close')
    },
    // 保存
    handleSubmit () {
      this.form.validateFields((err,data) => {
        console.log(data)
        console.log(this.selectMenu)
        console.log(this.postParams)
          this.selectMenu.ds.forEach(item =>{
            if(item.id==this.postParams.lqdsxm){
              this.postParams.lqdsxm = item.xm
            }
          })

           var params = Object.assign({
            id:this.postParams.id,
            lqdsId:this.postParams.lqdsId,
            lqdsmc:this.postParams.lqdsxm,
          })

          this.$api.doctorRecruit.bsnlqrymdUpdateBslqds(params).then( res =>{
             this.reset()
             this.form.resetFields()
             this.$emit('success')
          })
      })

    },
    handleDelete (key) {
      const dataSource = [...this.data]
      this.data = dataSource.filter(item => item.key !== key)
    }
  }
}
</script>
